<?php

class IdentitasController extends Controller
{
	public function actionIndex()
	{
		$this->render('index');
	}

	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			
		);
	}
        
        public function actionAutocomplete ($by) {
		  if (isset($_GET['term'])) {
                      
                     $criteria=new CDbCriteria;
                    if(isset($_GET['comparison']))
                        $criteria->condition = 't.'.$by." ".urldecode($_GET['comparison'])." '" . $_GET['term'] . "'";
                    else
                        $criteria->condition = 't.'.$by." like '" . $_GET['term'] . "%'";
                        
                    $criteria->with = array('Tamu');
                    
		    $dataProvider = new CActiveDataProvider(get_class(Identitas::model()), array(
			'criteria'  =>  $criteria, 
                        'pagination'    =>  false,
			));
		    $tamu = $dataProvider->getData();
                    
		    $return_array = array();
		    foreach($tamu as $value) {
		      $return_array[] = array(
		                    'label'=>$value->$by,
		                    'value'=>$value->$by,
                                    'id_identitas' => $value->id_identitas,
                                    'no_identitas' => $value->no_identitas,
                                    'tipe_identitas' => $value->tipe_identitas,
                                    'alamat' => $value->Tamu->alamat,
                                    'instansi' => $value->Tamu->Instansi->nama,
                                    'id_instansi' => $value->Tamu->Instansi->id_instansi,
                                    'no_hp'=> $value->Tamu->no_hp,
		                    'foto' => $value->Tamu->foto,
		                    'id_tamu'=>$value->Tamu->id_tamu,
                                    'nama_tamu'=>$value->Tamu->nama,
		                    );
		    }
		
		    echo CJSON::encode($return_array);
		  }
	}
}